﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.Serialization;

namespace Bing.Studio
{
    [Serializable]
    public class TableObject
    {
        public string Name { get; set; }

        public List<ColumnObject> Columns { get; set; }

        public TableObject()
        {
            Columns = new List<ColumnObject>();
        }
    }
    [Serializable]
    public class ColumnObject
    {
        public string Name { get; set; }
        public string DbType { get; set; }
        public int DbLength { get; set; }
        public bool IsIdentity { get; set; }
        public bool IsNull { get; set; }
        public bool IsPrimaryKey { get; set; }
        public string DefaultValue { get; set; }
        public string Description { get; set; }

        public string DbTypeAsCSharpType()
        {
            switch (DbType.ToLower())
            {
                case "datetime":
                    return "DateTime";
                case "varchar":
                case "nvarchar":
                case "char":
                case "nchar":
                case "text":
                case "ntext":
                case "date":
                case "time":
                case "xml":
                    return "string";
                case "uniqueidentifier":
                    return "Guid";
                case "bigint":
                    return "long";
                case "int":
                    return "int";
                case "smallint":
                    return "short";
                case "tinyint":
                    return "Byte";
                case "decimal":
                case "money":
                case "numeric":
                    return "decimal";
                case "image":
                    return "byte[]";
                case "float":
                    return "double";
                case "bit":
                    return "bool";
                default:
                    return "Object";
            }
        }
    }
}
